package com.njitzx.controller;


import com.njitzx.entity.dto.GoodCategoryDTO;
import com.njitzx.entity.po.GoodsCats;
import com.njitzx.service.GoodsCatsService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.njitzx.entity.vo.Result;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;



import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 商品分类表 前端控制器
 * </p>
 *
 * @author 周鑫
 * @since 2024-08-20
 */
@Api(tags = "商品分类表接口")
@RestController
@RequestMapping("/goods-cats")
@RequiredArgsConstructor
public class GoodsCatsController {

    private final GoodsCatsService goodsCatsService;

    @ApiOperation("商品分类表分页查询")
    @GetMapping("/list")
    public Result findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") Integer pageNum,
                               @ApiParam("页大小") @RequestParam(defaultValue = "5") Integer pageSize,
                               @ApiParam("查询条件") GoodsCats goodsCats){
        PageInfo<GoodsCats> pageInfo = goodsCatsService.findPage(pageNum,pageSize,goodsCats);
        return Result.success(pageInfo);
    }

    @ApiOperation("根据主键查询商品分类表")
    @GetMapping("/{catId}")
    public Result findById(@PathVariable Serializable catId){
        return Result.success(goodsCatsService.findById(catId));
    }

    @ApiOperation("新增商品分类表")
    @PostMapping
    public Result add(@RequestBody GoodCategoryDTO goodCategoryDTO){
        goodsCatsService.add(goodCategoryDTO);
        return Result.success();
    }

    @ApiOperation("修改商品分类表")
    @PutMapping
    public Result modify(@RequestBody GoodsCats goodsCats){
        goodsCatsService.modify(goodsCats);
        return Result.success();
    }

    @ApiOperation("根据主键删除商品分类表")
    @DeleteMapping("/{catId}")
    public Result removeById(@PathVariable Serializable catId){
        goodsCatsService.removeById(catId);
        return Result.success();
    }

}
